﻿// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import 'babel-polyfill'
import 'jquery'
import infiniteScroll from 'vue-infinite-scroll'
import Avue from '@smallwei/avue'
import VueAwesomeSwiper from 'vue-awesome-swiper'
import 'swiper/dist/css/swiper.css'
import '@smallwei/avue/lib/index.css'
import mavonEditor from 'mavon-editor'
import 'mavon-editor/dist/css/index.css'

import 'normalize.css/normalize.css'
import Element from 'element-ui'
import html2canvas from 'html2canvas'
// 引入store
import store from './store'
// 引入echarts
import echarts from 'echarts'
Vue.prototype.$echarts = echarts

import permission from './permission'

// 主题样式
// import '@/assets/theme/index.css'
// 全局css样式
import '@/styles/index.scss'

// 国际化
import i18n from './i18n'

// 接口数据模拟
import './mock'
import '../public/pro/common/message'

// 变为全局
Vue.use(Avue)
// 使用Element UI
Vue.use(Element, {
  i18n: (key, value) => i18n.t(key, value)
})

Vue.config.productionTip = false
Vue.use(infiniteScroll)
Vue.use(VueAwesomeSwiper)
Vue.use(mavonEditor)

/* eslint-disable no-new */

// 工单组件安装注册
// Vue.use(window.ews)
// Vue.component('CustomList', window.ews.default.CustomList)

/**
 * 数据字典翻译
 * @param item 每一项配置
 * @param data 数据对象
 */
Vue.filter('dataDicTrans', function(item, data) {
  if (!data) {
    return
  }
  // 有数据字典配置
  if (item.dicData) {
    // 一一对应解析
    if (item.type == 'select') {
      for (let i = 0; i < item.dicData.length; i++) {
        if (data[item.prop] == item.dicData[i].value) {
          return item.dicData[i].label
        }
      }
      return data[item.prop]
    }
  } else {
    // 掩码处理
    if (item.mask && window.Settings.maskSwitch) {
      if (item.mask == 'idCard' || item.mask == 'accountNo') {
        return Utils.maskNumbers(data[item.prop], 4)
      } else if (item.mask == 'mobilePhone') {
        return Utils.maskNumbers(data[item.prop], 3)
      }
    }
    return data[item.prop]
  }
})

new Vue({
  el: '#app', // 使用store
  components: { App },
  render: h => h(App),
  i18n,
  router,
  permission,
  html2canvas,
  store,
  template: '<App/>'
})
// 页面加载完成，给工作台发送完成指令
window.onload = function() {
  window.parent.postMessage({
    event: 'EventDomLoaded'
  }, '*')
}
